/* 
 * File:   AgentDB.h
 * Author: eduardo
 *
 * Created on 18 de noviembre de 2012, 20:28
 */

#ifndef AGENTDB_H
#define	AGENTDB_H

#include <odb/database.hxx>
#include <odb/mysql/database.hxx>
#include <string>
#include <memory>
#include <cstdlib>
#include <iostream>
#include <set>
#include <algorithm>
#include "DictionaryDB.h"
#include "DictionaryDB-odb.hxx"
#include "PostingFileDB.h"
#include "PostingFileDB-odb.hxx"
#include "IdDocs.h"
#include "IdDocs-odb.hxx"
using namespace std;
using namespace odb::core;
 
class AgentDB {
public:
    static AgentDB* getAgentePtr();
    void create_database(int& argc, char* argv[]);

    int existTerm(const string& term);
    void persistDictTerm(const string& term, int idT);
    void persistPFLine(int idPF, const vector<DocOccurrence>& vec);
    void persistIDDoc(int id, const string& name);

    void updateTerm(const string& term, const vector<DocOccurrence>& newvec);

    void getIdDocs(const string& term, set<int>* iddocs);
    void getTotalDocs(int* total);
    map<int, int> fillOccu(const string& term) const;
    
    int loadNTerms();
    int loadNDocs();

private:
    AgentDB();
    static AgentDB* _agent;
    database* _db;
};

#endif	/* AGENTDB_H */

